<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.example.el_jstl.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: LiuZiMing
  Date: 2023/3/23
  Time: 14:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--set标签--%>
<%--往域中保存数据--%>
保存之前:${requestScope.key1}<br>
<%--scope表示保存到哪个域  var表示设置的key是 value设置值--%>
<c:set scope="request" var="key1" value="value1"/>
保存之后:${requestScope.key1}<br>

<%--if标签--%>
<c:if test="${12 == 12}">
    <h2>
        12等于12
    </h2>
</c:if>

<%--choose标签--%>
<% request.setAttribute("height",180);%>
<c:choose>
    <c:when test="${requestScope.height < 170}">
        <h2>一米七以下</h2>
    </c:when>
    <c:when test="${requestScope.height >= 170}">
        <h2>一米七以上</h2>
    </c:when>
    <c:otherwise>
        <h2>身高错误</h2>
    </c:otherwise>
</c:choose>

<%--遍历--%>
<%--i为循环的变量--%>
<c:forEach begin="0" end="10" var="i">
    ${i}
</c:forEach>
<%--遍历Object数组--%>
<%
    request.setAttribute("arr",new String[]{"121312","132412","13414214"});
%>
<c:forEach items="${requestScope.arr}" var="item">
    ${item}<br>
</c:forEach>
<%--遍历Map--%>
<%
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
// for ( Map.Entry<String,Object> entry : map.entrySet()) {
// }
    request.setAttribute("map", map);
%>
<c:forEach items="${ requestScope.map }" var="entry">
    <h1>${entry.key} = ${entry.value}</h1>
</c:forEach>
<%--遍历List--%>
<%--4.遍历 List 集合---list 中存放 Student 类，有属性：编号，用户名，密码，年龄，电话信息--%>
<%
    List<Student> studentList = new ArrayList<Student>();
    for (int i = 1; i <= 10; i++) {
        studentList.add(new Student(i,"username"+i ,"pass"+i,18+i,"phone"+i));
    }
    request.setAttribute("stus", studentList);
%>
<table>
    <tr>
        <th>编号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>年龄</th>
        <th>电话</th>
        <th>操作</th>
    </tr>
    <%--
    items 表示遍历的集合
    var 表示遍历到的数据
    begin 表示遍历的开始索引值
    end 表示结束的索引值
    step 属性表示遍历的步长值
    varStatus 属性表示当前遍历到的数据的状态
    for（int i = 1; i < 10; i+=2）
    --%>
    <c:forEach begin="2"  end="7" step="2" varStatus="status" items="${requestScope.stus}" var="stu">
        <tr>
            <td>${stu.id}</td>
            <td>${stu.username}</td>
            <td>${stu.password}</td>
            <td>${stu.age}</td>
            <td>${stu.phone}</td>
            <td>${status.step}</td>
        </tr>
    </c:forEach>
</table>




</body>
</html>













